home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / qtstreamingapplet / src / qtstreamingapplet.java
Encoding:
Java Source  |  2000-06-23  |  2.3 KB  |  80 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.applet.Applet;
  9. import java.awt.*;
  10. import java.awt.event.*;
  11.  
  12. import quicktime.*;
  13. import quicktime.io.QTFile;
  14.  
  15. import quicktime.app.QTFactory;
  16. import quicktime.app.display.*;
  17. import quicktime.app.image.ImageDrawer;    // for exceptions
  18.  
  19. public class QTStreamingApplet extends Applet {
  20.     private Drawable myQTContent;
  21.     private QTCanvas myQTCanvas;
  22.     
  23.     public void init () {
  24.         try {
  25.             QTSession.open();
  26.                 // set up a QTCanvas which will disply its content 
  27.                 // at its original size of smaller and centered in the space given
  28.                 // to the QTCanvas when the applet is layed out
  29.             setLayout (new BorderLayout());
  30.             myQTCanvas = new QTCanvas (QTCanvas.kInitialSize, 0.5F, 0.5F);
  31.             add (myQTCanvas, "Center");        
  32.             
  33.             myQTContent = ImageDrawer.getQTLogo();
  34.         
  35.             final TextField urlTextField = new TextField ("file:///... Enter an URL to a movie", 30);//Enter URL to movie here", 30);
  36.             urlTextField.setFont (new Font ("Dialog", Font.PLAIN, 10));
  37.             urlTextField.setEditable (true);
  38.             urlTextField.addActionListener (new ActionListener () {
  39.                 TextField tf = urlTextField;
  40.                 
  41.                 public void actionPerformed (ActionEvent ae) {
  42.                     if (myQTCanvas != null) {
  43.                         try {
  44.                                 //tf.getText() returns the URL the user has entered
  45.                             myQTContent = QTFactory.makeDrawable (tf.getText());
  46.                             myQTCanvas.setClient (myQTContent, true);
  47.                         } catch (QTException e) {
  48.                                 //probably a non-fatal error that the Applet 
  49.                                 //should deal with more informatively
  50.                             e.printStackTrace();
  51.                         }
  52.                     }
  53.                 }
  54.             });
  55.             add (urlTextField, "South");
  56.         } catch (QTException qtE) {
  57.                 //in this case the only QTException is in QTSession.open()
  58.             throw new RuntimeException (qtE.getMessage());        
  59.         }
  60.     }    
  61.  
  62.     public void start () { 
  63.         try { // if QT was not successfully initialized the QTCanvas will be null
  64.             if (myQTCanvas != null)
  65.                 myQTCanvas.setClient (myQTContent, true);            
  66.         } catch (QTException e) {
  67.             e.printStackTrace();
  68.         }
  69.     }
  70.     
  71.     public void stop () { 
  72.         if (myQTCanvas != null)
  73.             myQTCanvas.removeClient();
  74.     }
  75.     
  76.     public void destroy () {
  77.         QTSession.close();
  78.     }
  79. }
  80.